<template>
    <div style="padding: 20px">
      <div class="headerBoxList">
        <svg width="24" height="24" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><rect x="4" y="14" width="36" height="20" rx="2" fill="none" stroke="#333" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/><path d="M42 20H44C45.1046 20 46 20.8954 46 22V26C46 27.1046 45.1046 28 44 28H42V20Z" fill="#333"/><path d="M13 21V27" stroke="#333" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/><path d="M19 21V27" stroke="#333" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/><path d="M25 21V27" stroke="#333" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/><path d="M31 24V27" stroke="#333" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"/></svg>
        <span style="margin-left: 10px">电量状态 </span>
      </div>
      <div class="contentBoxYY" style="">
        <!-- <el-collapse v-model="activeName" accordion>
          <el-collapse-item style="" v-for="(item,index) in listData" :key="index" :title="item" :name="index">
              <div style="background: #282828;color: rgb(101, 177, 235);padding-left:20px;border: none !important;" v-for="(data,j) in item.content" :key="j">
                    
              </div>
          </el-collapse-item>
        </el-collapse> -->
        <div style="height: 40px;font-size: 18px;border-bottom: 1px solid #e9e9e9;line-height: 40px;" v-for="(item,index) in listData" :key="index">{{ item }}</div>
      </div>
    </div>
</template>

  <script>
  import { getRxTmpPathApi } from '@/api/phoneInfo/index'
  export default {
    name: "Battery",
    data() {
      return {
        activeName: 1,
        listData:[],
        total:0
      };
    },
    mounted(){
    },
    created() {
      this.initFunction();
    },
    methods: {
 
      initFunction() {
        // let stringData = ``;
        
let node = this.$route.params.nodeData.data; 
      let dataJson = {
        "proof_num":node.proof_num,
        "rxTmpPath":'/'+node.subtype
      }
      getRxTmpPathApi(dataJson).then(res=>{
        console.log(res.data)
        let arr1 = res.data.split("\n")
        this.listData = arr1;
        console.log(arr1)
return
       const stringData = res.data;

        // 替换手机状态
        const targetChar = 'screen-off';
        const replacementChar = '屏幕关闭';
        const replacedStr = stringData.replace(new RegExp(targetChar, 'g'), replacementChar);
        
        const targetChar1 = 'screen-on';
        const replacementChar1 = '屏幕开启';
        const replacedStr1 = replacedStr.replace(new RegExp(targetChar1, 'g'), replacementChar1);

        const targetChar2 = 'power-save-off';
        const replacementChar2 = '性能模式';
        const replacedStr2 = replacedStr1.replace(new RegExp(targetChar2, 'g'), replacementChar2);

        const targetChar3 = 'power-save-on';
        const replacementChar3 = '低电量模式';
        const replacedStr3 = replacedStr2.replace(new RegExp(targetChar3, 'g'), replacementChar3);

        const targetChar4 = 'device-idle-off';
        const replacementChar4 = '系统空闲关闭状态';
        const replacedStr4 = replacedStr3.replace(new RegExp(targetChar4, 'g'), replacementChar4);

        const targetChar5 = 'device-idle-on';
        const replacementChar5 = '系统空闲开启状态';
        const replacedStr5 = replacedStr4.replace(new RegExp(targetChar5, 'g'), replacementChar5);


        // 设置截取标题数组
        const delimiters = [
          "Battery History",
          "Per-PID Stats:",
          "Discharge step durations:",
          "Daily stats:",
          'Daily from',
          'Statistics since last charge:',
          "Estimated power use (mAh):",
          "All kernel wake locks:",
          "All wakeup reasons:",
          "CPU freqs:"
        ];
  
        const dataArray = [];
        let currentData = "";
  
        for (let i = 0; i < delimiters.length; i++) {
          const delimiter = delimiters[i];
          const startIndex = replacedStr5.indexOf(delimiter);
          const endIndex =i < delimiters.length - 1? replacedStr5.indexOf(delimiters[i + 1]): replacedStr5.length;
  
          if (startIndex !== -1 && endIndex !== -1) {
            const data = replacedStr5.slice(startIndex, endIndex).trim();
            dataArray.push(data);
          }
        }

        let arr = [];
        // 格式化字符串数组为json数据
        for (let index = 0; index < dataArray.length; index++) {
          const element = dataArray[index];
          const originalString = element;
          const delimiter = "\n";
  
          const delimiterIndex = originalString.indexOf(delimiter);
  
          if (delimiterIndex !== -1) {
            const firstPart = originalString.substring(0, delimiterIndex).trim();
            const secondPart = originalString
              .substring(delimiterIndex + 1)
              .trim();
            let item = {
              titleKey: firstPart,
              content: secondPart.split("\n"),
            };
            arr.push(item);
          } else {
            console.log("Delimiter not found in the string.");
          }
          // arr.push(item)
        }
        this.listData = arr;
      }).catch(error=>{

      })

      },
    },
  };
  </script>
  
  <style scoped>
  .headerBoxList {
    width: 100%;
    height: 50px;
    border-bottom: 1px solid #d2d2d2;
    display: flex;
    align-items: center;
    font-size: 18px;
    font-weight: bold;
  }
  .contentBoxYY{
      width: 95%; 
      margin: 0 auto;
      overflow: hidden;
      height:95vh;
      overflow-y: auto;
  }
  @media screen and (min-width: 2360px) {
      .contentBoxYY{
          width: 95%; 
          margin: 0 auto;
          overflow: hidden;
          height:67vh;
          overflow-y: auto;
      }
  }
  
  </style>